﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TotalApplication.AngelSix;

namespace TotalApplication.attach
{
    public class TreeViewKeyProperty : BaseAttachedProperty<TreeViewKeyProperty,bool>
    {
        public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (sender is TreeView element)
            {
                bool IsUseful = (bool)e.NewValue;

                element.KeyDown -= Element_KeyDown;

                if (IsUseful) 
                {
                    element.KeyDown += Element_KeyDown;
                }

            }
        }

        private void Element_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.A:
                    {
                        // Do Something Good
                        ((TreeView)sender).RemoveSlectedItem();
                        break;
                    }
            }
        }
    }

    public static class TreeViewHelper
    {
        public static void RemoveSlectedItem(this TreeView treeView)
        {
            treeView.Items.Remove(treeView.SelectedItem);
        }
    }
}
